[EXERCISE 1]¶

Bang Santiago sbang@mail.austral.edu.ar

20210125_183154.jpg It's an image of the Sun behing a tree in the morning


[EXERCISE 2]¶

In [5]:
"""1. CREATE A NEW CELL BELOW THIS ONE AND ADD A MARKDOWN TITLE (HEADING 1) WITH THE TEXT "[EXERCISE 2]"

2. Create a new cell below the one with a markdown title of "[EXERCISE 2]" to solve the following exercise in python, it needs to be a CODE cell:

    Write a function rectangle_area(width, height) that takes the width and height of a rectangle as input and returns its area.

3. Add the instructions of the exercise as a comment in the code cell above the function definition.
4. DO NOT KEEP THE CELL WITH THESE INSTRUCTIONS."""

def rectangle_area(width, height):
    area=width*height
    return area

[EXERCISE 3]¶

In [9]:
"""1. CREATE A NEW CELL BELOW THIS ONE AND ADD A MARKDOWN TITLE (HEADING 1) WITH THE TEXT "[EXERCISE 3]"
2. Use your created function to calculate the area of a rectangle with width 3 and height 4. Another of width 5 and height 10, and another of width 8 and height 2. Show your results in the same cell with a description of each result. Similar to this example:

        `The area of a rectangle with width 3 and height 4 is 12.`
3. Add the instructions of the exercise as a comment in the code cell with the solution.
4. DO NOT KEEP THE CELL WITH THESE INSTRUCTIONS."""

width=3
height=4
print(f"The area of a rectangle with width {width} and height {height} is {rectangle_area(width, height)}.")

width=5
height=10
print(f"The area of a rectangle with width {width} and height {height} is {rectangle_area(width, height)}.")

width=8
height=2
print(f"The area of a rectangle with width {width} and height {height} is {rectangle_area(width, height)}.")
The area of a rectangle with width 3 and height 4 is 12.
The area of a rectangle with width 5 and height 10 is 50.
The area of a rectangle with width 8 and height 2 is 16.

[EXERCISE 5]¶

  1. CREATE A NEW CELL BELOW THIS ONE AND ADD A MARKDOWN TITLE (HEADING 1) WITH THE TEXT "[EXERCISE 5]"

  2. CREATE A NEW CELL BELOW THE ONE WITH THE MARKDOWN TITLE OF "[EXERCISE 5]" TO SOLVE THE FOLLOWING EXERCISE IN PYTHON:

    Write a function central_difference(f, x, h) that approximates the derivative of a function f at a point x using the Central Difference Approximation. The function should take the function f, the point at which the derivative needs to be approximated x, and the step size h as input, and return the approximate value of the derivative.

https://en.wikipedia.org/wiki/Finite_difference

  1. Create a new cell with examples of the use of the function central_difference(f, x, h) to approximate the derivative of the function f(x) = x^2 at x = 2 using h = 0.1, h = 0.01, and h = 0.001. Show your results in the same cell with a description of each result. Similar to this example:

     `The derivative of f(x) = x^2 at x = 2 using h = 0.1 is 4.1.`
    
    
  2. DO NOT KEEP THE CELL WITH THESE INSTRUCTIONS.

[EXERCISE 5]¶

In [19]:
def central_difference (f, x, h):
    result=f(x-h)
    return result

def f(x):
    result=x**2
    return result

print(central_difference(f, 2, 0.1))
4
3.61